package com.hzg.springcloud.feign;

import com.hzg.springcloud.fegin.IProductFeignApi;
import com.hzg.springcloud.domain.Product;
import com.hzg.springcloud.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ProductFeignClient implements IProductFeignApi {//实现api中的feign接口
    @Autowired
    private IProductService productService;

    @Value("${server.port}")
    private String port;
    @Override
    public Product get(Long id) {
        //System.out.println("ProductFeignClient.....get....");
        log.info("ProductFeignClient.....get....");
        Product product = productService.get(id);
      /*  try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
//熔断>模拟出现异常
//        int i=1/0;
        Product result = new Product();
        BeanUtils.copyProperties(product,result);
        result.setName(result.getName()+",data from "+port);
        return result;
    }
}